import os
from fpdf import FPDF

from PIL import Image

from util.console import *

pdf = FPDF()
pdf.set_auto_page_break(0)         # 自动分页设为False

path = r"./demo"
imagelist = [i for i in os.listdir(path)]


for image in sorted(imagelist):
    (w, h) = Image.open(os.path.join(path, image)).size
    p(w,h)
    pdf.add_page()
    # pdf.image(os.path.join(path, image), w=190, h=150)      # 指定宽高
    pdf.image(os.path.join(path, image),w+2,h+2)      # 指定宽高

pdf.output(os.path.join(path, "佩奇.pdf"), "F")